#include "stdinclude.h"
#include "utils/OsTools.h"




long WinOsTools::GetCurrentTimeInMillis()
{
	return ::GetTickCount();
	
}


void WinOsTools::Sleep(long millis)
{
	::Sleep(millis);
}

void WinOsTools::SleepSeconds(double sec)
{
	int milliSecs = int(sec * 1000.0);
	::Sleep(milliSecs);
}

void WinOsTools::DebugOut(const String& msg)
{
	OutputDebugStringA(msg.c_str());
}




//------------------------------------------------------------------------------
/**
	This displays a Win32 error message box and quits the program
*/
void
WinOsTools::Error(const String& error)
{
	#ifdef _DEBUG
	DebugOut(error);
	#endif
	
	
	MessageBoxA(NULL, error.c_str(), "SYSTEM ERROR", MB_OK|MB_APPLMODAL|MB_SETFOREGROUND|MB_TOPMOST|MB_ICONERROR);
	

	//abort();
}







// Deals with unicode/MBCS/char issues
LPCTSTR 
WinOsTools::toTCHAR(const String& str) 
{
#   if defined(_MBCS) || defined(_UNICODE)
	static const int LEN = 1024;
	static TCHAR x[LEN];

	MultiByteToWideChar(
		CP_ACP, 
		0, 
		str.c_str(), 
		-1, 
		x, 
		LEN);

	//swprintf(x, LEN, _T("%s"), str.c_str());
	return const_cast<LPCTSTR>(x);
#   else
	return str.c_str();
#   endif
}